core: Add "subpath" option to checkout
authorColin Walters <walters@verbum.org>
Tue, 6 Mar 2012 13:57:31 +0000 (08:57 -0500)
committerColin Walters <walters@verbum.org>
Tue, 6 Mar 2012 16:59:06 +0000 (11:59 -0500)
Will be used by ostbuild to extract e.g. /runtime or /devel from
artifacts.

src/ostree/ot-builtin-checkout.c
tests/t0000-basic.sh

index e7cc20a10578d72fd5da59b09080cb2795c250e0..f4730725f469d49a43f31a877b1147906cab547d 100644 (file)
 #include <glib/gi18n.h>
 
 static gboolean user_mode;
+static char *subpath;
 
 static GOptionEntry options[] = {
   { "user-mode", 'U', 0, G_OPTION_ARG_NONE, &user_mode, "Do not change file ownership or initialze extended attributes", NULL },
+  { "subpath", 0, 0, G_OPTION_ARG_STRING, &subpath, "Checkout sub-directory PATH", "PATH" },
   { NULL }
 };
 
@@ -45,7 +47,8 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error
   char *resolved_commit = NULL;
   const char *destination;
   OstreeRepoFile *root = NULL;
-  GFileInfo *root_info = NULL;
+  OstreeRepoFile *subtree = NULL;
+  GFileInfo *file_info = NULL;
   GFile *destf = NULL;
 
   context = g_option_context_new ("COMMIT DESTINATION - Check out a commit into a filesystem tree");
@@ -80,14 +83,23 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error
   if (!ostree_repo_file_ensure_resolved (root, error))
     goto out;
 
-  root_info = g_file_query_info ((GFile*)root, OSTREE_GIO_FAST_QUERYINFO,
+  if (subpath)
+    {
+      subtree = (OstreeRepoFile*)g_file_resolve_relative_path ((GFile*)root, subpath);
+    }
+  else
+    {
+      subtree = g_object_ref (root);
+    }
+
+  file_info = g_file_query_info ((GFile*)subtree, OSTREE_GIO_FAST_QUERYINFO,
                                  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
                                  cancellable, error);
-  if (!root_info)
+  if (!file_info)
     goto out;
 
   if (!ostree_repo_checkout_tree (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
-                                  destf, root, root_info, cancellable, error))
+                                  destf, subtree, file_info, cancellable, error))
     goto out;
 
   ret = TRUE;
@@ -98,6 +110,7 @@ ostree_builtin_checkout (int argc, char **argv, GFile *repo_path, GError **error
   g_clear_object (&repo);
   g_clear_object (&destf);
   g_clear_object (&root);
-  g_clear_object (&root_info);
+  g_clear_object (&subtree);
+  g_clear_object (&file_info);
   return ret;
 }
index bffed6fd3373aafd4b682fe9897b9c113f4d3a66..606ef38c872bde1853405a11e3978982472dde6e 100755 (executable)
@@ -19,7 +19,7 @@
 
 set -e
 
-echo "1..26"
+echo "1..27"
 
 . libtest.sh
 
@@ -190,3 +190,9 @@ cd ${test_tmpdir}
 $OSTREE cat test2 /yet/another/tree/green > greenfile-contents
 assert_file_has_content greenfile-contents "leaf"
 echo "ok cat-file"
+
+cd ${test_tmpdir}
+$OSTREE checkout --subpath /yet/another test2 checkout-test2-subpath
+cd checkout-test2-subpath
+assert_file_has_content tree/green "leaf"
+echo "ok checkout subpath"